import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";
import home from "@/views/home/index.vue";
import Login from "@/components/Login/index.vue";
import gameList from "@/views/gameList/index.vue";
import game2048 from "@/views/gameList/game2048/index.vue";
import useStore from "@/store/index.js";
// 创建路由
const routes = [
  //一个一个的路由规则
  {
    //路径
    path: "/",
    name: "index",
    //组件绑定
    redirect: "/login",
  },
  {
    //路径
    path: "/home",
    name: "home",
    //组件绑定
    component: home,
    children: [
      {
        //路径
        path: "/gameList",
        //组件绑定
        component: gameList,
        label: "游戏",
        children: [
          {
            //路径
            path: "/gameList/game2048",
            name: "gameList",
            //组件绑定
            component: () => import("../views/gameList/game2048/index.vue"),
          },
          {
            //路径
            path: "/gameList/findAGirl",
            name: "gameList",
            //组件绑定
            component: () => import("../views/gameList/findAGirl/index.vue"),
          },
        ],
      },
      {
        //路径
        path: "/fileList",
        //组件绑定
        component: gameList,
        label: "文件列表",
        children: [
          {
            //路径
            path: "/gameList/game2048",
            name: "gameList",
            //组件绑定
            component: () => import("../views/gameList/game2048/index.vue"),
          },
        ],
      },
      {
        //聊天客户端
        path: "/chatClient",
        name: "chatClient",
        //组件绑定
        component: () => import("../views/chatClient/index.vue"),
      },
    ],
  },
  {
    //路径
    path: "/login",
    name: "login",
    //组件绑定
    component: Login,
  },
];
console.log("process.env.NODE_ENV", process.env.NODE_ENV);

//创建路由器
const router = createRouter({
  history:
    process.env.NODE_ENV === "development"
      ? createWebHistory()
      : createWebHashHistory(),
  //管理路由
  routes: routes,
});

router.beforeEach((to, from, next) => {
  if (to.path === "/login") {
    next();
  } else {
    next();
    // let store = useStore();
    // store.menuStore.getMenuList();
    // console.log("store", store);
  }
});
export default router;
